//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.web.controller.sys;

import com.aidong.dao.base.ConditionMap;
import com.aidong.dao.base.OrderSet;
import com.aidong.dao.base.Pagination;
import com.aidong.model.wills.SysUserLog;
import com.aidong.util.ExportXls;
import com.aidong.web.controller.BaseController;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"sysUserLog"})
public class SysUserLogController extends BaseController {
    public SysUserLogController() {
    }

    @RequestMapping({"list"})
    public ModelAndView list() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return (new ModelAndView("sys/log/list")).addObject("userName", this.getTypeList("userName")).addObject("dt1", sdf.format(new Date(System.currentTimeMillis() - 86400000L))).addObject("dt2", sdf.format(new Date()));
    }

    @RequestMapping({"_list"})
    public ModelAndView _list(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "userCode",required = false) String userCode, @RequestParam(value = "operate",required = false) String operate, @RequestParam(value = "content",required = false) String content, @RequestParam(value = "ipAddr",required = false) String ipAddr, @RequestParam(value = "dateFrom",required = false) String dateFrom, @RequestParam(value = "dateTo",required = false) String dateTo, @RequestParam(value = "pageNo",required = false) String pageNo, @RequestParam(value = "totalCount",required = false) String totalCount) {
        Pagination pg = new Pagination(1, 20);
        pg.setPage(this.parseInt(pageNo), this.parseInt(totalCount));
        ConditionMap cd = new ConditionMap();
        this.addConditionShopCode(cd, "shopCode", shopCode);
        cd.eq("userCode", userCode);
        if(!this.chkNull(operate)) {
            cd.like("operate", "%" + operate + "%");
        }

        if(!this.chkNull(content)) {
            cd.like("content", "%" + content + "%");
        }

        if(!this.chkNull(ipAddr)) {
            cd.like("ipAddr", "%" + ipAddr + "%");
        }

        if(!this.chkNull(dateFrom)) {
            cd.ge("logTime", this.getDateFrom(dateFrom));
        }

        if(!this.chkNull(dateTo)) {
            cd.le("logTime", this.getDateTo(dateTo));
        }

        this.sysUserLogDao.queryPageList(pg, cd, (new OrderSet()).desc("logTime"));
        ModelAndView mv = new ModelAndView("sys/log/_list");
        mv.addObject("list", pg.getResultList());
        mv.addObject("pg", pg);
        return mv;
    }

    @RequestMapping({"expt"})
    public ModelAndView expt(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "userCode",required = false) String userCode, @RequestParam(value = "operate",required = false) String operate, @RequestParam(value = "content",required = false) String content, @RequestParam(value = "ipAddr",required = false) String ipAddr, @RequestParam(value = "dateFrom",required = false) String dateFrom, @RequestParam(value = "dateTo",required = false) String dateTo, HttpServletResponse response) {
        try {
            Pagination e = new Pagination(1, '\uea60');
            e.setPage(Integer.valueOf(1), Integer.valueOf(1));
            ConditionMap cd = new ConditionMap();
            this.addConditionShopCode(cd, "shopCode", shopCode);
            cd.eq("userCode", userCode);
            if(!this.chkNull(operate)) {
                cd.like("operate", "%" + operate + "%");
            }

            if(!this.chkNull(content)) {
                cd.like("content", "%" + content + "%");
            }

            if(!this.chkNull(ipAddr)) {
                cd.like("ipAddr", "%" + ipAddr + "%");
            }

            if(!this.chkNull(dateFrom)) {
                cd.ge("logTime", this.getDateFrom(dateFrom));
            }

            if(!this.chkNull(dateTo)) {
                cd.le("logTime", this.getDateTo(dateTo));
            }

            this.sysUserLogDao.queryPageList(e, cd, (new OrderSet()).desc("logTime"));
            ExportXls xls = new ExportXls(response, "系统日志", "系统日志");
            xls.addHead(new String[]{"时间", "操作员", "门店编号", "门店名称", "IP地址", "事件", "内容"});
            xls.setWidth(new int[]{20, 20, 10, 15, 20, 20, 30});
            new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Iterator i$ = e.getResultList().iterator();

            while(i$.hasNext()) {
                SysUserLog userLog = (SysUserLog)i$.next();
                xls.addRow(new Object[]{sdf2.format(userLog.getLogTime()), this.nvl(userLog.getUserCode()) + " - " + this.nvl(this.cache.getValue("userName", userLog.getUserCode())), userLog.getShopCode(), this.cache.getValue("shopName", userLog.getShopCode()), userLog.getIpAddr(), userLog.getOperate(), userLog.getContent()});
            }

            xls.close();
            this.addUserLog("导出系统日志", e.getResultList().size() + "条记录");
        } catch (Exception var16) {
            this.log.error("import", var16);
        }

        return null;
    }
}